
/**
 * @class
 * @constructor
 */
function Application() {
	
	var widget = null;
	
	var that = this;
	
	// called by this.init
	
	this.initWidget = function() {
		
		// initialise widget

		flyui.info("instantiate a service for the widget");
		var service = new flyui.flyatlas.Service();
		service.setEndpoint("../../../data/flyatlas");
		
		flyui.info("instantiate a renderer for the widget");
		var renderer = new flyui.flyatlas.Widget.DefaultRenderer(); 
		renderer.setCanvas($("#widgetCanvas"));
		
		flyui.info("instantiate a genefinder widget");
		widget = new flyui.flyatlas.Widget(service, renderer);

	};
	

	this.init = function() {
		
		var logReader = new YAHOO.widget.LogReader("logger");

		this.initWidget();

		// attach form submission listener to form
		flyui.info("hook form submission to widget call");
		YAHOO.util.Event.addListener("queryForm", "submit", this.onFormSubmitted);
		
		flyui.info("application loaded, showing main pane");
		$("#loadingPane").hide();
		$("#applicationPane").show();
	};
	
	
	this.onFormSubmitted = function(event) {
	    try {
    		flyui.info("form submitted");
    		var query = document.getElementById("queryInput").value;
    		var mode = document.getElementById("queryMode").selectedIndex;
    		flyui.debug("query: "+query);
    		flyui.debug("query mode: "+mode);
    		$("queryInput").value = "";
    		if (mode == 0) {
    			widget.getAssaysByAffyProbeId(query);
    		} else if (mode == 1) {
    		    var gene = new flyui.flybase.Gene();
    		    gene.flybaseID = query;
    			widget.getAssaysByGene(gene);		
    		} else {
    			flyui.err("unexpected query mode");
    		}
	    }
        catch (error) {
            flyui.err(error.name+" "+error.message);
        }
	};

	this.init();
}

// on dom ready, instantiate application
YAHOO.util.Event.onDOMReady(function() {new Application();});